package com.lm.common.core.exception;

/**
 * @author lm
 * @date 2019/5/23 14:59
 */
public class BizException extends RuntimeException {

    public static final String SUCCESS = "200";
    public static final String WARN = "300";
    public static final String ERROR = "500";

    public final String code;

    public String getCode() {
        return this.code;
    }

    public BizException(String code, String msg) {
        super(msg);
        if (SUCCESS.equals(code)) {
            this.code = "sys.bizException";
        } else {
            this.code = code;
        }
    }

    public BizException(String msg, Throwable e) {
        super(msg, e);
        BizAssert.notNull(e);
        this.code = e.getClass().getName();
    }

    public BizException(Throwable e) {
        super(e);
        BizAssert.notNull(e);
        this.code = e.getClass().getName();
    }

    public BizException(String code) {
        this(code, code);
    }

    public static void fail(String code, String msg) {
        throw new BizException(code, msg);
    }

    public static void fail(String code) {
        throw new BizException(code);
    }

}